<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/commons/global.jsp"%>

<div id="category-setting-div" class="easyui-window" title="设置类别"
	style="width: 1000px; height: 500px"
	data-options="iconCls:'icon-cog',modal:true,openAnimation:'fade',closeAnimation:'slide',cache:false,collapsible:false,minimizable:false,maximizable:false">
	<div class="content-wrapper">
		<div class="title-wrapper" style="float: left; width: 640px;">
			<%-- 			<div>资源类型:${itemType.code }</div> --%>
			<div style="float: left; width: 100px;">资源类型:${itemType.msg }</div>
			<div style="float: left; width: 100px;">资源ID:${entity.id }</div>
			<div style="float: left;">标题:${entity.title }</div>
			<div style="clear: both;"></div>
			<div>
				<img alt="" src="${entity.coverUrl }"
					style="width: 640px; height: 360px;" />
			</div>
		</div>

		<div class="category-wrapper" style="float: right; width: 300px;">
			<div class="title">
				<input id="setCategory_categoryContentTree_categoryNameQue"
					style="width: 200px;" />
			</div>
			<div class="content"></div>
		</div>
		<div style="clear: both;"></div>
	</div>
</div>


<script type="text/javascript">
	function setCategory_categoryContentTree_categoryTreesReload() {
		try {
			$(setCategory_categoryContentTree_categoryTrees)
					.each(
							function(_inx, _val) {
								$(_val).tree("options").queryParams = {
									like_name : setCategory_categoryContentTree_categoryNameQue
											.textbox('getValue')
								};
								$(_val).tree('reload');
							});
		} catch (e) {
		}
	}
</script>


<script type="text/javascript">
	var setCategory_categoryContentTree_categoryNameQue = undefined;
	var setCategory_categoryContentTree_categoryTrees = new Array();
	$(function() {
		setCategory_categoryContentTree_categoryNameQue = $(
				'#setCategory_categoryContentTree_categoryNameQue').textbox({
			buttonText : '类别名搜索',
			buttonIcon : 'icon-search',
			buttonAlign : 'right'
		});

		setCategory_categoryContentTree_categoryNameQue.textbox('button')
				.click(function() {
					setCategory_categoryContentTree_categoryTreesReload();
				});

		var category_setting_div = $('#category-setting-div').window({
			onBeforeClose : function() {

			},
			onClose : function() {
				category_setting_div.panel('destroy');
				try {
					categoryVideoListDatagrid.datagrid('reload');
				} catch (e) {
				}
			}
		});

		$
				.ajax({
					async : false,
					url : baseUrl + '/category/top/list/${itemType.code}',
					success : function(dCategoryDatas) {
						$(dCategoryDatas)
								.each(
										function(_inx, _val) {
											$(
													'#category-setting-div .category-wrapper .content')
													.append(
															'<div id="'+_val.attribute.ckey+'CategoryContent" style="padding: 5px"><ul id="'+_val.attribute.ckey+'CategoryContentTree"></ul></div>');

											$(
													'#' + _val.attribute.ckey
															+ 'CategoryContent')
													.panel(
															{
																tools : [ {
																	iconCls : 'icon-save',
																	handler : function() {
																		var nodes = $(
																				'#'
																						+ _val.attribute.ckey
																						+ 'CategoryContentTree')
																				.tree(
																						'getChecked');
																		if (!nodes
																				|| nodes.length < 1) {
																			$.messager
																					.alert(
																							'提示',
																							'请选择'
																									+ _val.text,
																							'warning');
																			return;
																		}
																		var textArr = new Array();
																		var typeArr = new Array();

																		for ( var i = 0; i < nodes.length; i++) {
																			textArr
																					.push(nodes[i].text);
																			typeArr
																					.push(nodes[i].id);
																		}
																		$.messager
																				.confirm(
																						'确认',
																						_val.text
																								+ ':'
																								+ textArr
																										.join(',')
																								+ '<br />确定设置?',
																						function(
																								r) {
																							if (r) {
																								var _data = {
																									ckey : _val.attribute.ckey,
																									categoryIds : typeArr,
																									itemType : '${itemType.code}',
																									itemId : '${entity.id}'
																								};
																								$
																										.ajax({
																											type : 'post',
																											async : false,
																											data : _data,
																											url : baseUrl
																													+ '/category/set',
																											success : function(
																													responseData) {
																												$.messager
																														.alert(
																																'提示',
																																'添加成功',
																																'info');
																											}
																										});
																							}
																						});
																	}
																} ],
																width : 300,
																title : '设置'
																		+ _val.text
															});

											var setCategory_categoryContentTree_categoryTree = $(
													'#'
															+ _val.attribute.ckey
															+ 'CategoryContentTree')
													.tree(
															{
																url : '${baseUrl }/category/get/'
																		+ _val.id
																		+ '?itemId=${entity.id }&itemType=${itemType.code }',
																method : 'post',
																animate : true,
																checkbox : true,
																onlyLeafCheck : true,
																lines : true
															});
											setCategory_categoryContentTree_categoryTrees
													.push(setCategory_categoryContentTree_categoryTree);
										});
					}
				});
	});
</script>